{{--预约核酸--}}
    <!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>预约核酸</title>
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>


<a href="{{url('rt/registration')}}"  class="btn btn-primary">预约挂号</a>
<button class="btn btn-light">预约核酸</button>
<a href="{{url('rt/scheduling')}}" class="btn btn-primary">医生排班</a>
<br>
{{--单选框--}}
<input name="sel" class="type" value="" checked type="radio">全部
<input name="sel" class="type" value="1" type="radio">待检测
<input name="sel" class="type" value="2" type="radio">已检测
<input name="sel" class="type" value="0" type="radio">已取消
<table class="layui-hide" id="test" lay-filter="test">

</table>

</body>
</html>
<script type="text/html" id="toolbarDemo">
    <div>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加预约</button>
        <input class="text"  class="layui-form-label" name="" id="name" placeholder="请输入姓名">
        <button class="layui-btn layui-btn-sm" lay-event="sel">搜索</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" style="color:#fff;">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="color:#fff;">删除</a>
</script>


<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'http://medical.com/rtAdm/admin_nat'/*tpa=https://www.layuiweb.com/test/table/demo1.json*/
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'预约ID', width:80, fixed: 'left', sort: true}
                ,{field:'users.0.name', title:'患者名', width:120, edit: 'text',templet:function (d) {
                        return  d.users['0'].name
                    }}
                ,{field:'sd_card', title:'就诊卡号', width:120, edit: 'text'}
                ,{field:'id_card', title:'身份证号', width:170, edit: 'text',templet:function (d){
                        return  d.users['0'].id_card
                    }}
                ,{field:'phone', title:'手机号', width:150, edit: 'text',templet:function (d){
                        return  d.users['0'].phone
                    }}
                ,{field:'office', title:'挂号科室', width:80, edit: 'text'}
                ,{field:'nat_ree', title:'核酸费用', width:80, edit: 'text'}
                ,{field:'sign', title:'挂号状态',width: 100,templet:function (d){
                        if(d.type==1){
                            return "<button class=\"layui-btn layui-btn-danger  layui-btn-xs\">未检测</button>";
                        }else if(d.type==2){
                            return "<button  class=\"layui-btn layui-btn-xs\">已检测</button>";
                        }else if(d.type==0){
                            return "<button  class=\"layui-btn layui-btn-primary layui-btn-xs\">已取消</button>";
                        }
                    }}
                ,{field:'data', title:'就诊日期', width:80, sort: true}
                ,{field:'time', title:'候诊时间', width:120}
                ,{field:'created_at', title:'预约时间', width:120,edit:'time'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //单选框
        $('.type').click(function () {
            let type=$(this).val()??'';
            // layer.msg(type)
            table.reload('test',{
                url:'http://medical.com/rtAdm/admin_nat'
                ,where:{
                    type:type,
                    page:1
                }
            })
        })
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            console.log('asd');
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'sel':
                    let name=$('#name').val();
                    table.reload('test',{
                        url:'http://medical.com/rtAdm/admin_nat'
                        ,where: {
                            name:name,
                            page:1
                        }
                    })
            }
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //删除行
            if(obj.event === 'del'){
                let id=data.id;
                layer.confirm('真的删除行么', function(index){
                    $.get(
                        "http://medical.com/rtAdm/admin_nat_del?id="+id,
                        function (res) {
                            let val=JSON.parse(res);
                            if(val.code==0){
                                layer.msg('删除成功');
                                obj.del();
                                layer.close(index);
                            }else if(val.code!=0){
                                layer.msg('删除失败')
                            }
                        }
                    )
                });
            }
            else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>


